package sortdemo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 04
 * Time:11:29
 */
//冒泡排序
public class bubblesort {
    public void bubble(int[] nums,int size){
        for (int i = 0; i < size - 1 ; i++) {//共 n - 1趟排序
            boolean flag = false;
            for (int j = 0; j < nums.length - i ; j++) {
                if(nums[j] > nums[j + 1]){
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
            if(flag == false){
                return;
            }
        }
    }
}
